#include <DApplication>
#include <DMainWindow>
#include <DWidgetUtil>
#include <DApplicationSettings>
#include <DTitlebar>
#include <DProgressBar>
#include <DFontSizeManager>

#include <QPropertyAnimation>
#include <QDate>
#include <QLayout>
#include "weather.h"
#include "citycode.h"
#include <DLineEdit>
#include <DPushButton>
#include <QObject>
#include <QJsonDocument>


DWIDGET_USE_NAMESPACE

int main(int argc, char *argv[])
{
    QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
    DApplication a(argc, argv);
    a.setOrganizationName("deepin");
    a.setApplicationName("天气预报");
    a.setApplicationVersion("1.0");
    a.setProductIcon(QIcon(":/images/logo1.svg"));
    a.setProductName("天气预报");
    a.setApplicationDescription("一款实时天气查询应用");

    a.loadTranslator();
    a.setApplicationDisplayName(QCoreApplication::translate("Main", "DTK Application"));
    a.setStyleSheet(
            "QToolTip {"
            "   color: red;" // 设置工具提示的字体颜色为红色
            "   background-color: white;" // 设置工具提示的背景颜色为白色
            "}"
        );


    // 保存程序的窗口主题设置
    DApplicationSettings as;
    Q_UNUSED(as)

    weather w;
    w.titlebar()->setIcon(QIcon(":/images/logo1.svg"));
    w.setWindowIcon(QIcon(":/images/logo1.svg"));

    DLineEdit *searchBox = new DLineEdit();
    DPushButton * btnSearch = new DPushButton("搜索");
    QObject::connect(btnSearch, &DPushButton::clicked, [&]{

        cityCode m;
        QString citycode = m.getCityCode(searchBox->text());
        if (citycode.isEmpty()){
            qDebug()<<"未找到";
             w.sendMessage(w.style()->standardIcon(QStyle::SP_MessageBoxWarning), "请检查输入城市名称");
        }else{
            w.getWeather(citycode);
        }

    });

    searchBox->setPlaceholderText("输入城市名称...");
    w.titlebar()->addWidget(searchBox);
    w.titlebar()->addWidget(btnSearch);
    w.show();


    Dtk::Widget::moveToCenter(&w);

    return a.exec();
}
